package com.example.zsf.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.zsf.R;
import com.example.zsf.activity.common.ImageBrowserActivity;
import com.example.zsf.model.CollectRecordModel;
import com.example.zsf.model.MobileDetailModel;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CollectedInfoDialog extends Dialog {

    private Context context;
    private final MobileDetailModel.MobileDetailCollectedRecordModel model;
    private final CollectRecordModel.CollectRecordListModel data;
    @BindView(R.id.textView63)
    TextView gameName_tv;
    @BindView(R.id.textView62)
    TextView gameID_tv;
    @BindView(R.id.textView61)
    TextView gameIP_tv;
    @BindView(R.id.textView60)
    TextView gameMoney_tv;
    @BindView(R.id.textView59)
    TextView getTime_tv;
    @BindView(R.id.textView58)
    TextView editTime_tv;
    @BindView(R.id.textView57)
    TextView status_tv;

    public CollectedInfoDialog(@NonNull Context context, MobileDetailModel.MobileDetailCollectedRecordModel model, CollectRecordModel.CollectRecordListModel data) {
        super(context, R.style.CustomDialog);
        this.context = context;
        this.model = model;
        this.data = data;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.collect_info_dialog);
        ButterKnife.bind(this);
        initUI();
    }

    private void initUI() {
        if (model != null) {
            gameName_tv.setText(model.getAds_name());
            gameID_tv.setText(model.getRcv_game_name());
            gameIP_tv.setText(model.getRcv_open_name());
            gameMoney_tv.setText(model.getRcv_price());
            getTime_tv.setText(model.getRcv_time());
            editTime_tv.setText(model.getRcv_deal_time());

            int status = Integer.parseInt(model.getRcv_status());
            switch (status) {
                case 0:
                    status_tv.setText("待充值");
                    break;
                case 1:
                    status_tv.setText("已充值");
                    break;
                case 2:
                    status_tv.setText("异常");
                    break;
                case 3:
                    status_tv.setText("已退回");
                    break;
                case 4:
                    status_tv.setText("待填写");
                    break;
            }
        } else {
            gameName_tv.setText(data.getAds_name());
            gameID_tv.setText(data.getRcv_game_name());
            gameIP_tv.setText(data.getRcv_open_name());
            gameMoney_tv.setText(data.getRcv_price());
            getTime_tv.setText(data.getRcv_time());
            editTime_tv.setText(data.getRcv_deal_time());

            int status = Integer.parseInt(data.getRcv_status());
            switch (status) {
                case 0:
                    status_tv.setText("待充值");
                    break;
                case 1:
                    status_tv.setText("已充值");
                    break;
                case 2:
                    status_tv.setText("异常");
                    break;
                case 3:
                    status_tv.setText("已退回");
                    break;
                case 4:
                    status_tv.setText("待填写");
                    break;
            }
        }
    }


    @OnClick({R.id.imageView8, R.id.textView70})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.imageView8: {
                cancel();
            }
            break;
            case R.id.textView70: {
                ArrayList<MobileDetailModel.BannerImageInfo> bannerImageInfos = new ArrayList<>();
                MobileDetailModel.BannerImageInfo imageInfo =
                        new MobileDetailModel.BannerImageInfo();
                imageInfo.setImg_url(model != null ? model.getRcv_pay_img_url() : data.getRcv_pay_img_dir());
                bannerImageInfos.add(imageInfo);
                Intent intent = new Intent(context, ImageBrowserActivity.class);
                intent.putParcelableArrayListExtra("banner_image_infos", bannerImageInfos);
                context.startActivity(intent);
            }
            break;
        }
    }
}
